package com.jielin.handling.service.accesspath.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jielin.handling.mapper.accesspath.AccessPathMapper;
import com.jielin.handling.mapper.role.RoleMapper;
import com.jielin.handling.service.accesspath.AccessPathService;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by WR on 2019-04-01.
 */
@Service
@Slf4j
public class AccessPathServiceImpl implements AccessPathService {
	@Autowired
	AccessPathMapper accessPathMapper;
	@Autowired
	RoleMapper roleMapper;

	@Override
	public List<String> findAllPowerPathByPoliceId(String policeId) {
		List<String> roleIds = roleMapper.findRoleIdByPoliceId(policeId);// 用户角色信息
		if (roleIds.size() > 0) {
			List<String> roleAccessPathIdS = accessPathMapper.findAllPowerPathByRoleIdS(roleIds);// 根据角色id查询可访问的路径id
			if (roleAccessPathIdS.size() > 0) {
				List<String> roleAccessPathS = accessPathMapper.findAllPathByPathIdS(roleAccessPathIdS);// 根据路径id查询可访问的路径
				return roleAccessPathS;
			}
		}
		return null;
	}

	@Override
	public List<String> findPowerPathPageByPoliceId(String policeId) {
		List<String> roleIds = roleMapper.findRoleIdByPoliceId(policeId);// 用户角色信息
		if (roleIds.size() > 0) {
			List<String> roleAccessPathIdS = accessPathMapper.findAllPowerPathByRoleIdS(roleIds);// 根据角色id查询可访问的路径id
			if (roleAccessPathIdS.size() > 0) {
				List<String> roleAccessPathPages = accessPathMapper.findAllPathPageByPathIdS(roleAccessPathIdS);// 根据路径id查询可访问的页面
				return roleAccessPathPages;
			}
		}
		return null;
	}

	@Override
	public boolean findPowerIsBig(String policeId) {
		int weights = roleMapper.findPowerIsBig(policeId);
		return weights < 6 ? true : false;
	}

}
